package com.newgrand.annexserver.controller;

import com.newgrand.annexcommon.model.Result;
import com.newgrand.annexcommon.utils.ResultUtil;
import com.newgrand.annexserver.service.AttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * @author ：minyang
 * @date ：Created in 2019/8/15 11:47
 */
@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    AttachmentService attachmentService;

    @GetMapping("/demo1")
    public String demo1(HttpServletRequest req) {
        try {
//            String account = (String) req.getAttribute("account");
//            int tenantId = (int) req.getAttribute("tenantId");
            return "success";
        } catch (Exception e) {
            return "exception";
        }
    }

    @GetMapping("/addAttachment")
    public String addAttachment(HttpServletRequest req) {
        try {
            int result = attachmentService.addAttachment();
            return String.valueOf(result);
        } catch (Exception e) {
            return "exception";
        }
    }

    @GetMapping("/getAttachmentList")
    public Result getAttachmentList(HttpServletRequest req) {
        try {
            List result = attachmentService.getAttachmentList();
            return ResultUtil.success(result);
        } catch (Exception e) {
            return ResultUtil.fail(e.getMessage());
        }
    }


}
